<%@ page import="com.wzy.Jdbc封装.pojo.News_category" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:useBean id="category" class="com.wzy.level.category.categoryServiceImpl.categoryServiceImpl" />
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>inputSQLData</title>
</head>
<body>
<%--<jsp:include page="commen.jsp"/>--%>
<%--<jsp:forward page="detail.jsp"/>--%>


<div>
    <h1>news_category表</h1>

<%--    <table>--%>
<%--    <%--%>
<%--            List<News_category> news_categories = category.selectAll();--%>
<%--            for(int i = 0; i<news_categories.size();++i){--%>


<%--    %>--%>
<%--    <tr>--%>
<%--    <td><%=news_categories.get(i).getId()%></td>--%>
<%--    <td><%=news_categories.get(i).getName()%></td>--%>
<%--    <td><%=news_categories.get(i).getDate()%></td>--%>
<%--        <td><a href="category_del.jsp?id=<%=news_categories.get(i).getId()%>">删除</a></td>--%>
<%--        <td><a href="category_insert_update.jsp?state=0&id=<%=news_categories.get(i).getId()%>">修改</a></td>--%>
<%--        <td><a href="category_insert_update.jsp?state=1&id=<%=news_categories.get(i).getId()%>">新增</a></td>--%>
<%--    </tr>--%>

<%--    <%--%>
<%--            }--%>
<%--    %>--%>

<%--    </table>--%>



    <c:forEach var="category" varStatus="id" items="${sessionScope.news_categories}" end="${total}">

        <tr >
        <%--分开判断就可以隔行不一样的颜色--%>
        <c:if test="${id.count % 2 !=0}">
            <tr bgcolor="#F1A8A8FF">
        </c:if>
        <c:if test="${id.count % 2 ==0}">
            <tr bgcolor="#DFB3F6CC">
        </c:if>
        <td style="width: 50px">${category.id}</td>
        <td style="width: 100px">${category.name}</td>
        <td>
            <fmt:formatDate value="${category.date}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
        <td onclick="del(${category.id})">删除</td>
        <td><a href="/category_insert_updateServlet?state=0&id=${category.id}">修改</a></td>
        <td><a href="/category_insert_updateServlet?state=1&id=${category.id}">新增</a></td>
        </tr>
    </c:forEach>
    <tr>
        <td><a href="/pageManage?index=1&count=${sessionScope.count}&cate=4">首页</a></td>
        <td style="width: 100px"><a href="/pageManage?index=${(sessionScope.index)<0? 0:(index)}&count=${sessionScope.count}&cate=4">&lt;&lt;上一页</a></td>
        <td><a href="/pageManage?index=${(sessionScope.index+2)}&count=${sessionScope.count}&cate=4">下一页&gt;&gt;</a></td>
        <td><a href="/pageManage?index=${totalPage}&count=${sessionScope.count}&cate=4">尾页</a></td>
        <td>第${sessionScope.index+1}页</td>
        <td>共${(total % sessionScope.count == 0) ? totalPage : totalPage+1}页</td>
        <td>共${total}条记录</td>
        <td>
            <form action="/pageManage" method="get" style="margin: 0 auto">
                一页查<input type="text" name="count" style="width: 50px" >条数据&nbsp;
                <input type="text" name="cate" style="width: 50px" value="4" hidden >
                跳转至
                <input type="text" name="index" style="width: 50px"  >
                页
                <input type="submit" value="GO">
            </form>
        </td>


    </tr>


    </table>
</div>
<script type="text/javascript">
    function del(id){
        //创建对象
        var obj = new XMLHttpRequest();
        //建立连接 连接到服务器
        var url = "/category_delete?id="+id;
        obj.open("get",url,true);
        //发出请求
        obj.send();
        //服务端响应
        obj.onreadystatechange = function (){
            if(obj.readyState == 4 && obj.status == 200){
                // alert("请求成功!"+obj.responseText );
                var text = obj.responseText;
                if(text == 1){
                    alert("删除成功")
                    //刷新页面
                    window.location.href="/pageManage?cate=4";
                }else {
                    alert("删除失败")
                }
            }
        }
    }
</script>

<%--<iframe style="width: 1000px" src="detail.jsp">--%>
<%--</iframe>--%>
</body>
</html>